package org.hu.vhr.service;

import org.hu.vhr.mapper.InterviewMapper;
import org.hu.vhr.model.Interview;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service
public class InterviewService {
    @Autowired
    InterviewMapper interviewMapper;

    public Integer insertInterview(Interview interview){
        interview.setStatus(0);
        Calendar c = Calendar.getInstance();
        c.setTime(interview.getTime());
        c.add(Calendar.HOUR_OF_DAY,-1);
        Date startTime = c.getTime();
        c.setTime(interview.getTime());
        c.add(Calendar.HOUR_OF_DAY,1);
        Date endTime = c.getTime();
        System.out.println(startTime);
        System.out.println(endTime);
        Integer result = interviewMapper.selectByInterviewer(interview.getInterviewer(), startTime, endTime);
        if(result == null){
            return interviewMapper.insertSelective(interview);
        }else{
            return 0;
        }
    }

    public List<Interview> getAllInterview() {
        return interviewMapper.getAllInterview();
    }

    public Integer updateStatus(Interview interview) {
        return interviewMapper.updateByPrimaryKeySelective(interview);
    }

    public List<Interview> getAllNewEmps() {
        return interviewMapper.getAllNewEmps();
    }

    public int updateInfoStatus(Interview interview) {
        interview.setInfostatus(0);
        return interviewMapper.updateByPrimaryKeySelective(interview);
    }
}
